package com.ncu.web.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ncu.web.entry.Admin;
import com.ncu.web.entry.ReturnData;
import com.ncu.web.entry.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;

import java.sql.Timestamp;
import java.util.List;

/**
 * @Author:大润发杀鱼匠
 * @Date:2024/5/26 19:30 web
 */

@Repository
public interface UserMapper extends BaseMapper<Student> {

    @Select("SELECT * FROM contacts WHERE phone = #{phone}")
    Student selectByPhone(long phone);

    @Select("SELECT * FROM contacts WHERE email = #{email}")
    Student selectByEmail(String Email);

    @Update("UPDATE student SET login_times=#{loginTimes} WHERE id = #{id}")
    int updateLoginTimesInt(String id, int loginTimes);

    @Update("UPDATE student SET last_login_time=#{lastLoginTime} WHERE id = #{id}")
    int updateLastLoginTime(String id, Timestamp lastLoginTime);

    /**
     * 修改学生权限
     * @param id
     * @param permission
     */
    @Update("update student set permission=#{permission} where id=#{id}")
    void updatePermissionById(String id,short permission);

    /**
     * 查询所有学生信息
     * @return
     */
    @Select("select student.id, student.name,student.permission,student.password,student.login_times,student.last_login_time"+
            ",contacts.class_num, contacts.entry_year, contacts.graduate_year, contacts.employers, contacts.city, contacts.phone, " +
            "contacts.email, contacts.majority from student,contacts " +
            "where student.contacts=contacts.id")
    List<ReturnData> selectListAll();

    /**
     * 查询未通过授权的学生
     * @return
     */
    @Select("select student.id, student.name,student.permission,student.password,student.login_times,student.last_login_time"+
            ",contacts.class_num, contacts.entry_year, contacts.graduate_year, contacts.employers, contacts.city, contacts.phone, " +
            "contacts.email, contacts.majority from student,contacts " +
            "where student.contacts=contacts.id and student.permission=0")
    List<ReturnData> selectListAllFailed();

    /**
     * 查询单个学生的学生
     * @return
     */
    @Select("select student.id, student.name,student.permission,student.password,student.login_times,student.last_login_time"+
            ",contacts.class_num, contacts.entry_year, contacts.graduate_year, contacts.employers, contacts.city, contacts.phone, " +
            "contacts.email, contacts.majority from student,contacts " +
            "where student.contacts=contacts.id and student.id= #{id}")
    List<ReturnData> selectStudentById(String id);


    @Update("update student set password = #{password}, name = #{name} where id = #{id}")
    int updateStudent(String password, String name, String id);
}
